package driver.nxt.events;

import icommand.nxt.SensorPort;
import icommand.nxt.TouchSensor;
import driver.events.Event;
import driver.exceptions.SensorException;

/**
 * Provides a mechanism for reading from the NXT Touch Sensor
 *
 * @author David Martin
 */
public class NXTTouchEvent extends Event
{

  private static final String EVENT_NAME = "Touch Sensor";
  private TouchSensor sensor;

  /**
   * Assigns the sensor port for the NXT Touch sensor
   */
  public NXTTouchEvent()
  {
    super();
    sensor = new TouchSensor(SensorPort.S1);
  }

  public String getEventName()
  {
    return EVENT_NAME;
  }

  /**
   * Gets the latest reading from the touch sensor, where 0 means it isn't
   * pressed and 1 means it is pressed
   *
   * @return 1 if the sensor is activated, 0 otherwise
   * @throws driversuite.exceptions.SensorException
   */
  public String readFromSensor() throws SensorException
  {
    return sensor.isPressed() ? "1" : "0";
  }

  public String getMeasurementUnits()
  {
    return "";
  }
}
